package com.example.itcacp.controller;

import com.example.itcacp.dto.response.Result;
import com.example.itcacp.entity.Message;
import com.example.itcacp.service.MessageService;
import com.example.itcacp.service.WebSocketServer;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class WebSocketController {

    // 注入
    @Resource
    private WebSocketServer webSocketServer;

    // 发送消息
    @GetMapping("/send")
    public Result send(@RequestParam String token, @RequestBody Message message) {
        webSocketServer.sendToOne ( token, message.getContent () );
//            保存聊天记录到数据库
//            messageService.saveMessage ( message );
    return Result.success ();
    }
}
